package com.goldstone.dao;

import org.springframework.stereotype.Component;
import org.springside.modules.orm.hibernate.HibernateDao;

import com.goldstone.entity.Product;

@Component
public class ProductDao extends HibernateDao<Product, String> {
	public void save(Product product) {
		if(product == null) {
			product.setProNum(getMaxNum() + 1); 
		}
		System.out.println("Product.ID::" + product.getId());
		if(product.getId() != null) {
			getSession().update(product);
		}
		super.save(product);
	}
	
	public Integer getMaxNum() {
		Object max = getSession().createQuery("select max(proNum) from Product " ).uniqueResult();
		return max == null ? 0 : (Integer)max;
	}
}
